//
//  Env.swift
//  Casecord
//
//  Created by baozi on 2024/1/3.
//

import Foundation
import MMKV
/// 当前环境
struct Env: Codable, Equatable {
    var name: String
    
    var host: String
    
    var identify: String
    
    var webBaseUrl: String
    
    var fileUploadUrl: String
    
    var aesKey: String
    
    var systemSessionId: Int
    /// 客服id
    var serviceSessionId: Int
    /// 陌生人id
    var strangerSessionId: Int
    /// 网络请求前缀 zsa_
    var httpScheme: String
    /// 网络请求前缀 1
    var platformType: Int
    /// 网络请求前缀 7
    var appType: Int
    
    var privicyUrl: String
    
    var termsUrl: String
    
    var appStoreUrl: String
    
    /// 当前环境
    static var current: Env = {
        #if DEBUG || TEST
        KVStore[.env] ?? Env.test
        #else
        Env.test
        #endif
    }()
    
    /// 测试环境
    static let test: Env = Env(
        name: "测试环境",
        host: "https://dev.secmetchat.com",
        identify: "test",
        webBaseUrl: "",
        fileUploadUrl: "https://d7rx2jlt514t2.cloudfront.net",
        aesKey: "123456",
        systemSessionId: 99999,
        serviceSessionId: 551,
        strangerSessionId: -99999,
        httpScheme: "joymet_",
        platformType: 1,
        appType: 7,
        privicyUrl: "https://static.secmetchat.com/Secmet/PrivacyPolicy.html",
        termsUrl: "https://static.secmetchat.com/Secmet/TermsAndConditions.html",
        appStoreUrl: "itms-apps://itunes.apple.com/app/id41447812?action=write-review" // 414478124微信id
    )
    
    /// 测试环境
    static let testZSA: Env = Env(
        name: "测试环境HC",
        host: "http://apitest.zsachat.com",
        identify: "test",
        webBaseUrl: "",
        fileUploadUrl: "https://d7rx2jlt514t2.cloudfront.net",
        aesKey: "123456",
        systemSessionId: 99999,
        serviceSessionId: 551,
        strangerSessionId: -99999,
        httpScheme: "zsa_",
        platformType: 1,
        appType: 4,
        privicyUrl: "https://zsachat.com/app/LitmetPrivicys.html",
        termsUrl: "https://zsachat.com/app/LitmetTerm.html",
        appStoreUrl: "itms-apps://itunes.apple.com/app/id414478124?action=write-review"
    )
    
    /// 正式环境
    static let prod: Env = Env(
        name: "正式环境",
        host: "https://api.zsachat.com",
        identify: "prod",
        webBaseUrl: "",
        fileUploadUrl: "https://file.zsachat.com",
        aesKey: "zsaeE3mU",
        systemSessionId: 99999,
        serviceSessionId: 541056,
        strangerSessionId: -99999,
        httpScheme: "zsa_",
        platformType: 1,
        appType: 7,
        privicyUrl: "https://zsachat.com/app/LitmetPrivicys.html",
        termsUrl: "https://zsachat.com/app/LitmetTerm.html",
        appStoreUrl: "itms-apps://itunes.apple.com/app/id414478124?action=write-review"
    )
    
    // MARK: Action
    static func changeEnv(env: Env) {
        KVStore[.env] = env
        current = env
    }
    
    static func == (lhs: Self, rhs: Self) -> Bool {
        return lhs.host == rhs.host
    }
}
